from selenium.webdriver.common.by import By
# TODO 导入select类
from selenium.webdriver.support.ui import Select
from selenium import webdriver
import time


# 打开游览器和网页
driver = webdriver.Chrome()
driver.get('https://sahitest.com/demo')
# 找到下拉框页面进入
driver.find_element(By.LINK_TEXT,'Select Test').click()
# 定位一个下拉框点击
time.sleep(2)
s1 = driver.find_element(By.ID,'s1')
# 创建select对象，参数是要操作的select标签
select = Select(s1)

# 通过索引选择选项，从0开始
select.select_by_index(1)
time.sleep(2)
# 通过value选择选项，是字符串
select.select_by_value('49')
time.sleep(2)
# 通过文本选择选项
select.select_by_visible_text('Mail')
time.sleep(2)
# 关闭游览器
driver.quit()